package com.dong.c04_selector;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * <h1></h1>
 * se
 * @author : dzj
 * @create: 2020-03-18 16:01
 */
public class NIOClient {
    public static void main(String[] args) throws IOException {
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.configureBlocking(false);
        InetSocketAddress address = new InetSocketAddress("localhost", 6666);
        if(!socketChannel.connect(address)) {
            while(!socketChannel.finishConnect()) {
                System.out.println("因为连接需要时间, 客户端不会阻塞, 可以干别的");
            }
        }
        //连接成功, 发送数据
        String str= "hello , 尚硅谷";
        ByteBuffer buffer = ByteBuffer.wrap(str.getBytes());
        //发送数据
        socketChannel.write(buffer);
         System.in.read();
      //  socketChannel.close();


    }
}
